package com.youlu.campus.service.base.impl;

import com.youlu.campus.entity.TestReplicaMongo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.concurrent.ThreadLocalRandom;

@Service
public class TestReplicaMongoService {

    @Autowired
    private MongoTemplate mongoTemplate;

    public void findAll(){
        mongoTemplate.find(new Query(), TestReplicaMongo.class);
    }

    public void insert(){
        TestReplicaMongo testReplicaMongo = new TestReplicaMongo();
        testReplicaMongo.setName(ThreadLocalRandom.current().toString());
        mongoTemplate.save(testReplicaMongo);
    }
}
